package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Mnxp;
import com.ruoyi.system.service.IMnxpService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 母牛系谱Controller
 * 
 * @author ruoyi
 * @date 2025-02-16
 */
@RestController
@RequestMapping("/system/mnxp")
public class MnxpController extends BaseController
{
    @Autowired
    private IMnxpService mnxpService;

    /**
     * 查询母牛系谱列表
     */
    @PreAuthorize("@ss.hasPermi('system:mnxp:list')")
    @GetMapping("/list")
    public TableDataInfo list(Mnxp mnxp)
    {
        startPage();
        List<Mnxp> list = mnxpService.selectMnxpList(mnxp);
        return getDataTable(list);
    }

    /**
     * 导出母牛系谱列表
     */
    @PreAuthorize("@ss.hasPermi('system:mnxp:export')")
    @Log(title = "母牛系谱", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Mnxp mnxp)
    {
        List<Mnxp> list = mnxpService.selectMnxpList(mnxp);
        ExcelUtil<Mnxp> util = new ExcelUtil<Mnxp>(Mnxp.class);
        util.exportExcel(response, list, "母牛系谱数据");
    }

    /**
     * 获取母牛系谱详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:mnxp:query')")
    @GetMapping(value = "/{标准牛号}")
    public AjaxResult getInfo(@PathVariable("标准牛号") String 标准牛号)
    {
        return success(mnxpService.selectMnxpBy标准牛号(标准牛号));
    }

    /**
     * 新增母牛系谱
     */
    @PreAuthorize("@ss.hasPermi('system:mnxp:add')")
    @Log(title = "母牛系谱", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Mnxp mnxp)
    {
        return toAjax(mnxpService.insertMnxp(mnxp));
    }

    /**
     * 修改母牛系谱
     */
    @PreAuthorize("@ss.hasPermi('system:mnxp:edit')")
    @Log(title = "母牛系谱", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Mnxp mnxp)
    {
        return toAjax(mnxpService.updateMnxp(mnxp));
    }

    /**
     * 删除母牛系谱
     */
    @PreAuthorize("@ss.hasPermi('system:mnxp:remove')")
    @Log(title = "母牛系谱", businessType = BusinessType.DELETE)
	@DeleteMapping("/{标准牛号s}")
    public AjaxResult remove(@PathVariable String[] 标准牛号s)
    {
        return toAjax(mnxpService.deleteMnxpBy标准牛号s(标准牛号s));
    }
}
